package vip.xiaonuo.megvii.facegroups.delete.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vip.xiaonuo.megvii.facegroups.delete.FaceGroupDeleteStrategy;
import vip.xiaonuo.modular.facegroupfacetokenrela.entity.FacegroupFacetokenRela;
import vip.xiaonuo.modular.facegroupfacetokenrela.param.FacegroupFacetokenRelaParam;
import vip.xiaonuo.modular.facegroupfacetokenrela.service.FacegroupFacetokenRelaService;
import vip.xiaonuo.modular.megviifacegroup.entity.MegviiFaceGroup;
import vip.xiaonuo.modular.megviifacegroup.service.MegviiFaceGroupService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 保留人脸
 * 以分组为切入点，删除所有的关联
 */
@Service
public class DeleteFaceGroupSaveFace extends DeleteFaceGroupBaseService implements FaceGroupDeleteStrategy {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(MegviiFaceGroup group) {
        // 先找到与当前分组相关联的所有关联表
        List<FacegroupFacetokenRela> relas = getRelas(relaService,group.getId());
        // 删除关联表
        relaService.removeBatchByIds(relas);
        // 删除分组表
        groupService.removeById(group);

        // 删除分组关联
        this.deleteFaceGroupOrgRelate(groupOrgRelateService,group.getId());
    }

}
